load("@build_bazel_rules_nodejs//:index.bzl", "copy_to_bin", "pkg_npm")
load("//:packages.bzl", "VERSION_PLACEHOLDER_REPLACEMENTS")
load("//tools:defaults.bzl", "jasmine_node_test", "ts_library")

package(default_visibility = ["//visibility:public"])

copy_to_bin(
    name = "schematics_assets",
    srcs = ["ng-update/migrations/hammer-gestures-v9/gesture-config.template"] + glob([
        "ng-generate/*/files/**/*",
        "**/*.json",
    ]),
)

ts_library(
    name = "schematics",
    srcs = glob(
        ["**/*.ts"],
        exclude = [
            "**/*.spec.ts",
            "ng-update/test-cases/**/*.ts",
            "ng-generate/*/files/**/*.ts",
        ],
    ),
    # Schematics do not need to run in browsers and can use `commonjs`
    # as format instead the default `umd` format.
    devmode_module = "commonjs",
    module_name = "@angular/material/schematics",
    prodmode_module = "commonjs",
    tsconfig = ":tsconfig.json",
    deps = [
        "//src/cdk/schematics",
        "@npm//@angular-devkit/core",
        "@npm//@angular-devkit/schematics",
        "@npm//@schematics/angular",
        # TODO(devversion): Only include jasmine for test sources (See: tsconfig types).
        "@npm//@types/jasmine",
        "@npm//@types/node",
        "@npm//tslint",
        "@npm//typescript",
    ],
)

# This package is intended to be combined into the main @angular/material package as a dep.
pkg_npm(
    name = "npm_package",
    substitutions = VERSION_PLACEHOLDER_REPLACEMENTS,
    deps = [
        ":schematics",
        ":schematics_assets",
    ],
)

### Testing rules

jasmine_node_test(
    name = "unit_tests",
    srcs = [":unit_test_sources"],
    data = [
        ":schematics_assets",
        ":schematics_test_cases",
    ],
)

ts_library(
    name = "unit_test_sources",
    testonly = True,
    srcs = glob(
        ["**/*.spec.ts"],
        exclude = [
            "**/*.e2e.spec.ts",
            "ng-generate/*/files/**/*.spec.ts",
        ],
    ),
    tsconfig = ":tsconfig.json",
    deps = [
        ":schematics",
        "//src/cdk/schematics",
        "//src/cdk/schematics/testing",
        "//src/cdk/testing/private",
        "@npm//@angular-devkit/core",
        "@npm//@angular-devkit/schematics",
        "@npm//@schematics/angular",
        "@npm//@types/fs-extra",
        "@npm//@types/jasmine",
        "@npm//@types/node",
        "@npm//fs-extra",
    ],
)

filegroup(
    name = "schematics_test_cases",
    testonly = True,
    srcs = glob([
        "ng-update/test-cases/**/*_input.ts",
        "ng-update/test-cases/**/*_expected_output.ts",
    ]),
)
